/**
 * 
 */
package it.rainbowbreeze.polygen.data.webservice;

import it.rainbowbreeze.polygen.common.AppEnv;
import it.rainbowbreeze.polygen.common.ResultOperation;
import it.rainbowbreeze.polygen.util.TestHelper;
import android.content.Context;
import android.test.AndroidTestCase;
import android.text.TextUtils;

/**
 * @author rainbowbreeze
 *
 */
public class WebserviceManagerTest extends AndroidTestCase {
    WebserviceManager mWebserviceManager;
    
    public WebserviceManagerTest() {
        // TODO Auto-generated constructor stub
    }
    
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        Context context = getContext();
        assertNotNull("Context is null", context);
        TestHelper.init(context);
        
        mWebserviceManager = AppEnv.i(context).getWebserviceManager();
        assertNotNull(mWebserviceManager);
    }
    
    public void testGetMessage() {
        ResultOperation<String> result = mWebserviceManager.getMessageFromSection("http://www.polygen.org/polygen/remote/ita/basket.grm");
        assertFalse("Has errors", result.hasErrors());
        assertFalse("Empty response", TextUtils.isEmpty(result.getResult()));
    }

    public void testDoNotRepeatSameMessage() {
        ResultOperation<String> result1 = mWebserviceManager.getMessageFromSection("http://www.polygen.org/polygen/remote/ita/basket.grm");
        assertFalse("Has errors", result1.hasErrors());
        assertFalse("Empty response", TextUtils.isEmpty(result1.getResult()));

        ResultOperation<String> result2 = mWebserviceManager.getMessageFromSection("http://www.polygen.org/polygen/remote/ita/basket.grm");
        assertFalse("Has errors", result2.hasErrors());
        assertFalse("Empty response", TextUtils.isEmpty(result2.getResult()));
        
        assertFalse("Same message", result1.getResult().equals(result2.getResult()));
    }

    
}
